﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;
using RelationTextBox;

namespace Administrare
{
    public partial class MeniuriFrm : FrmRezumat
    {
        public DataSet result = new DataSet();
        public BindingSource bs = new BindingSource();
        public MeniuriFrm(ModuleClass mInfo)
            : base(mInfo)
        {
            InitializeComponent();
            workConnString = "AdminConnectionString";
       
            result.Tables.Add("Metode");
            result.Tables["Metode"].Columns.Add("nume_metoda");
            bs.DataSource = result;
            bs.DataMember = "Metode";

            this.handlerNameColumn.DataSource = bs;
            this.handlerNameColumn.DisplayMember = "nume_metoda";
            this.handlerNameColumn.ValueMember = "nume_metoda";

        }

        private void MeniuriFrm_Load(object sender, EventArgs e)
        {
            listBndSourceMain.Add(admin_ApplicationMenuBindingSource);
            listTableAdaptor.Add(admin_ApplicationMenuTableAdapter.Adapter);
            //FrmMainMdi frm = MdiParent as FrmMainMdi;
            //frm.GetModuleSelectMethodList(String.Empty, ref result);
            SqlConnection con = DeschideConexiune(workConnString);
            this.aspnet_ApplicationsTableAdapter.Connection = con;
            this.aspnet_ApplicationsTableAdapter.Fill(this.adminDataSet.aspnet_Applications);
            this.admin_ApplicationMenuTableAdapter.Connection = con;
            this.admin_ApplicationMenuTableAdapter.Fill(this.adminDataSet.admin_ApplicationMenu);
            InchideConexiune(con);

            HandleSalvare += Salvare;
            //applicationNameCB_SelectedValueChanged(applicationNameCB, null);
        }

        private void applicationNameCB_SelectedValueChanged(object sender, EventArgs e)
        {
            if (applicationNameCB.SelectedValue == null)
                return;
            aspnetApplicationsBindingSource.Filter = "ApplicationId='" + applicationNameCB.SelectedValue.ToString() + "'";

            AdminDataSet.aspnet_ApplicationsRow rM = ((DataRowView)aspnetApplicationsBindingSource.Current).Row
                as AdminDataSet.aspnet_ApplicationsRow;
            FrmMainMdi frm = MdiParent as FrmMainMdi;
            frm.GetModuleSelectMethodList(rM.NumeDLL, ref result);
            //admin_ApplicationMenuBindingSource.ResetBindings(true);
            adminApplicationMenuBindingSource.Filter = "ApplicationId='" + rM.ApplicationId.ToString() + "'";
        }

        override public void Salvare(object sender, EventArgs args)
        {
            MyTrace("Salvare");
            base.Salvare(this, args);
            if (EroareSalvare)
                return;
            SqlConnection con = DeschideConexiune(workConnString);
            this.admin_ApplicationMenuTableAdapter.Connection = con;
            this.admin_ApplicationMenuTableAdapter.Fill(this.adminDataSet.admin_ApplicationMenu);

            InchideConexiune(con);

        }

    }
}
